package com.itheima;

import com.itheima.dao.UserDao;
import com.itheima.dao.impl.UserDaoImpl;
import com.itheima.domain.User;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AppForIoc {
    public static void main(String[] args) {
        User user = new User();
        user.setId(100L);
        user.setUserName("Spring小能手");
        user.setAge(21);

       /* UserDao userDao = new UserDaoImpl();
        userDao.save(user);*/

       /* //1.创建IOC容器对象，加载Spring核心配置文件
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        //2.从IOC容器中获取Bean对象（UserDao对象）
        UserDao bootuser = (UserDao) context.getBean("bootuser");
        //3.调用Bean对象（UserDao对象）的方法
        bootuser.save(user);*/

        //创建IOC容器对象，加载Spring核心配置文件
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
       //从IOC容器中获取Bean对象
        UserDao userDao = (UserDao) ctx.getBean("userDao");
        userDao.save(user);



    }
}
